/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.eclipselabs.damos.dml.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipselabs.damos.dml.BlockType;
import org.eclipselabs.damos.dml.CategorizedElement;
import org.eclipselabs.damos.dml.Category;
import org.eclipselabs.damos.dml.DMLPackage;
import org.eclipselabs.damos.dml.InputDefinition;
import org.eclipselabs.damos.dml.NamedElement;
import org.eclipselabs.damos.dml.OutputDefinition;
import org.eclipselabs.damos.dml.internal.operations.CategorizedElementOperations;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Block Type</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.eclipselabs.damos.dml.impl.BlockTypeImpl#getBelongingCategories <em>Belonging Categories</em>}</li>
 *   <li>{@link org.eclipselabs.damos.dml.impl.BlockTypeImpl#getName <em>Name</em>}</li>
 *   <li>{@link org.eclipselabs.damos.dml.impl.BlockTypeImpl#getInputs <em>Inputs</em>}</li>
 *   <li>{@link org.eclipselabs.damos.dml.impl.BlockTypeImpl#getOutputs <em>Outputs</em>}</li>
 *   <li>{@link org.eclipselabs.damos.dml.impl.BlockTypeImpl#getId <em>Id</em>}</li>
 *   <li>{@link org.eclipselabs.damos.dml.impl.BlockTypeImpl#isOutputDataTypeSpecifiable <em>Output Data Type Specifiable</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BlockTypeImpl extends ParameterableElementImpl implements BlockType {
	/**
	 * The cached value of the '{@link #getBelongingCategories() <em>Belonging Categories</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBelongingCategories()
	 * @generated
	 * @ordered
	 */
	protected EList<Category> belongingCategories;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * This is true if the Name attribute has been set.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 * @ordered
	 */
	protected boolean nameESet;

	/**
	 * The cached value of the '{@link #getInputs() <em>Inputs</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInputs()
	 * @generated
	 * @ordered
	 */
	protected EList<InputDefinition> inputs;

	/**
	 * The cached value of the '{@link #getOutputs() <em>Outputs</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOutputs()
	 * @generated
	 * @ordered
	 */
	protected EList<OutputDefinition> outputs;

	/**
	 * The default value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected static final String ID_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected String id = ID_EDEFAULT;

	/**
	 * The default value of the '{@link #isOutputDataTypeSpecifiable() <em>Output Data Type Specifiable</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isOutputDataTypeSpecifiable()
	 * @generated
	 * @ordered
	 */
	protected static final boolean OUTPUT_DATA_TYPE_SPECIFIABLE_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isOutputDataTypeSpecifiable() <em>Output Data Type Specifiable</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isOutputDataTypeSpecifiable()
	 * @generated
	 * @ordered
	 */
	protected boolean outputDataTypeSpecifiable = OUTPUT_DATA_TYPE_SPECIFIABLE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BlockTypeImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DMLPackage.Literals.BLOCK_TYPE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Category> getBelongingCategories() {
		if (belongingCategories == null) {
			belongingCategories = new EObjectResolvingEList<Category>(Category.class, this, DMLPackage.BLOCK_TYPE__BELONGING_CATEGORIES);
		}
		return belongingCategories;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		boolean oldNameESet = nameESet;
		nameESet = true;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DMLPackage.BLOCK_TYPE__NAME, oldName, name, !oldNameESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void unsetName() {
		String oldName = name;
		boolean oldNameESet = nameESet;
		name = NAME_EDEFAULT;
		nameESet = false;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.UNSET, DMLPackage.BLOCK_TYPE__NAME, oldName, NAME_EDEFAULT, oldNameESet));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isSetName() {
		return nameESet;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<InputDefinition> getInputs() {
		if (inputs == null) {
			inputs = new EObjectContainmentEList<InputDefinition>(InputDefinition.class, this, DMLPackage.BLOCK_TYPE__INPUTS);
		}
		return inputs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<OutputDefinition> getOutputs() {
		if (outputs == null) {
			outputs = new EObjectContainmentEList<OutputDefinition>(OutputDefinition.class, this, DMLPackage.BLOCK_TYPE__OUTPUTS);
		}
		return outputs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isOutputDataTypeSpecifiable() {
		return outputDataTypeSpecifiable;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setOutputDataTypeSpecifiable(boolean newOutputDataTypeSpecifiable) {
		boolean oldOutputDataTypeSpecifiable = outputDataTypeSpecifiable;
		outputDataTypeSpecifiable = newOutputDataTypeSpecifiable;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DMLPackage.BLOCK_TYPE__OUTPUT_DATA_TYPE_SPECIFIABLE, oldOutputDataTypeSpecifiable, outputDataTypeSpecifiable));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean belongsTo(String categoryId) {
		return CategorizedElementOperations.belongsTo(this, categoryId);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getId() {
		return id;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setId(String newId) {
		String oldId = id;
		id = newId;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DMLPackage.BLOCK_TYPE__ID, oldId, id));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case DMLPackage.BLOCK_TYPE__INPUTS:
				return ((InternalEList<?>)getInputs()).basicRemove(otherEnd, msgs);
			case DMLPackage.BLOCK_TYPE__OUTPUTS:
				return ((InternalEList<?>)getOutputs()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case DMLPackage.BLOCK_TYPE__BELONGING_CATEGORIES:
				return getBelongingCategories();
			case DMLPackage.BLOCK_TYPE__NAME:
				return getName();
			case DMLPackage.BLOCK_TYPE__INPUTS:
				return getInputs();
			case DMLPackage.BLOCK_TYPE__OUTPUTS:
				return getOutputs();
			case DMLPackage.BLOCK_TYPE__ID:
				return getId();
			case DMLPackage.BLOCK_TYPE__OUTPUT_DATA_TYPE_SPECIFIABLE:
				return isOutputDataTypeSpecifiable();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case DMLPackage.BLOCK_TYPE__BELONGING_CATEGORIES:
				getBelongingCategories().clear();
				getBelongingCategories().addAll((Collection<? extends Category>)newValue);
				return;
			case DMLPackage.BLOCK_TYPE__NAME:
				setName((String)newValue);
				return;
			case DMLPackage.BLOCK_TYPE__INPUTS:
				getInputs().clear();
				getInputs().addAll((Collection<? extends InputDefinition>)newValue);
				return;
			case DMLPackage.BLOCK_TYPE__OUTPUTS:
				getOutputs().clear();
				getOutputs().addAll((Collection<? extends OutputDefinition>)newValue);
				return;
			case DMLPackage.BLOCK_TYPE__ID:
				setId((String)newValue);
				return;
			case DMLPackage.BLOCK_TYPE__OUTPUT_DATA_TYPE_SPECIFIABLE:
				setOutputDataTypeSpecifiable((Boolean)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DMLPackage.BLOCK_TYPE__BELONGING_CATEGORIES:
				getBelongingCategories().clear();
				return;
			case DMLPackage.BLOCK_TYPE__NAME:
				unsetName();
				return;
			case DMLPackage.BLOCK_TYPE__INPUTS:
				getInputs().clear();
				return;
			case DMLPackage.BLOCK_TYPE__OUTPUTS:
				getOutputs().clear();
				return;
			case DMLPackage.BLOCK_TYPE__ID:
				setId(ID_EDEFAULT);
				return;
			case DMLPackage.BLOCK_TYPE__OUTPUT_DATA_TYPE_SPECIFIABLE:
				setOutputDataTypeSpecifiable(OUTPUT_DATA_TYPE_SPECIFIABLE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DMLPackage.BLOCK_TYPE__BELONGING_CATEGORIES:
				return belongingCategories != null && !belongingCategories.isEmpty();
			case DMLPackage.BLOCK_TYPE__NAME:
				return isSetName();
			case DMLPackage.BLOCK_TYPE__INPUTS:
				return inputs != null && !inputs.isEmpty();
			case DMLPackage.BLOCK_TYPE__OUTPUTS:
				return outputs != null && !outputs.isEmpty();
			case DMLPackage.BLOCK_TYPE__ID:
				return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id);
			case DMLPackage.BLOCK_TYPE__OUTPUT_DATA_TYPE_SPECIFIABLE:
				return outputDataTypeSpecifiable != OUTPUT_DATA_TYPE_SPECIFIABLE_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eBaseStructuralFeatureID(int derivedFeatureID, Class<?> baseClass) {
		if (baseClass == CategorizedElement.class) {
			switch (derivedFeatureID) {
				case DMLPackage.BLOCK_TYPE__BELONGING_CATEGORIES: return DMLPackage.CATEGORIZED_ELEMENT__BELONGING_CATEGORIES;
				default: return -1;
			}
		}
		if (baseClass == NamedElement.class) {
			switch (derivedFeatureID) {
				case DMLPackage.BLOCK_TYPE__NAME: return DMLPackage.NAMED_ELEMENT__NAME;
				default: return -1;
			}
		}
		return super.eBaseStructuralFeatureID(derivedFeatureID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public int eDerivedStructuralFeatureID(int baseFeatureID, Class<?> baseClass) {
		if (baseClass == CategorizedElement.class) {
			switch (baseFeatureID) {
				case DMLPackage.CATEGORIZED_ELEMENT__BELONGING_CATEGORIES: return DMLPackage.BLOCK_TYPE__BELONGING_CATEGORIES;
				default: return -1;
			}
		}
		if (baseClass == NamedElement.class) {
			switch (baseFeatureID) {
				case DMLPackage.NAMED_ELEMENT__NAME: return DMLPackage.BLOCK_TYPE__NAME;
				default: return -1;
			}
		}
		return super.eDerivedStructuralFeatureID(baseFeatureID, baseClass);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		if (nameESet) result.append(name); else result.append("<unset>");
		result.append(", id: ");
		result.append(id);
		result.append(", outputDataTypeSpecifiable: ");
		result.append(outputDataTypeSpecifiable);
		result.append(')');
		return result.toString();
	}

} //BlockTypeImpl
